def maxProfit(prices):
    """
    计算股票交易中的最大利润
    :param prices: 股票价格的数组，例如 [7, 1, 5, 3, 6, 4]
    :return: 最大利润
    """
    if not prices:
        return 0

    min_price = prices[0]
    max_profit = 0

    for price in prices:
        if price < min_price:
            min_price = price
        else:
            max_profit = max(max_profit, price - min_price)

    return max_profit


if __name__ == '__main__':
    print(maxProfit([7, 1, 5, 3, 6, 4]))
    print(maxProfit([7, 6, 4, 3, 1]))
